package com.dcy.workflow.controller;

import com.dcy.common.base.controller.DcyBaseController;
import com.dcy.common.model.PageModel;
import com.dcy.common.model.PageResult;
import com.dcy.common.model.R;
import com.dcy.workflow.service.ActModelService;
import com.dcy.workflow.vo.in.ModelCreateInVO;
import com.dcy.workflow.vo.in.ModelSearchInVO;
import com.dcy.workflow.vo.in.ModelUpdateInVO;
import com.dcy.workflow.vo.out.ModelListOutVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;

/**
 * @Author：dcy
 * @Description:
 * @Date: 2021/6/7 10:55
 */
@RequiredArgsConstructor
@Validated
@Slf4j
@RestController
@RequestMapping("/flow/model")
@Api(value = "ModelController", tags = {"模型操作接口"})
public class ModelController extends DcyBaseController {

    private final ActModelService actModelService;

    @ApiOperation(value = "获取模型列表")
    @GetMapping(value = "/page")
    public R<PageResult<ModelListOutVO>> page(ModelSearchInVO modelSearchInVO, PageModel pageModel) {
        return success(actModelService.modelPageList(modelSearchInVO, pageModel));
    }

    @ApiOperation(value = "创建流程")
    @PostMapping(value = "/create")
    public R<Boolean> createModel(@Validated @ApiParam @RequestBody ModelCreateInVO modelSaveInputDTO) {
        return success(actModelService.createModel(modelSaveInputDTO));
    }

    @ApiOperation(value = "修改流程")
    @PostMapping(value = "/update")
    public R<Boolean> updateModel(@Validated @ApiParam @RequestBody ModelUpdateInVO modelUpdateInVO) {
        return success(actModelService.updateModel(modelUpdateInVO));
    }

    @ApiOperation(value = "获取流程json信息")
    @ApiImplicitParam(name = "modelId", value = "模型id", dataType = "String", paramType = "query", required = true)
    @GetMapping(value = "/getModelJsonById")
    public R<String> getModelJsonById(@NotBlank(message = "模型id不能为空") String modelId) {
        return success(actModelService.getModelJsonByModelId(modelId));
    }


    @ApiOperation(value = "部署模型")
    @ApiImplicitParam(name = "modelId", value = "模型id", dataType = "String", paramType = "query")
    @PostMapping(value = "deploy")
    public R<Boolean> deploy(@NotBlank(message = "模型id不能为空") String modelId) {
        return success(actModelService.deployModel(modelId));
    }


    @ApiOperation(value = "删除模型")
    @ApiImplicitParam(name = "modelId", value = "模型id", dataType = "String", paramType = "query")
    @PostMapping(value = "delete")
    public R<Boolean> delete(@NotBlank(message = "模型id不能为空") String modelId) {
        return success(actModelService.deleteModel(modelId));
    }

}
